package com.xiaoha.pogy.dao;

import com.xiaoha.pogy.dto.BookBorrow;
import com.xiaoha.pogy.entities.Book;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BookRepository extends CrudRepository<Book , Long> {

    @Override
    List<Book> findAll();
    @Query(nativeQuery = true,value = "SELECT s.name, s.number_id AS numberId, COUNT(s.book_id) AS borrowCount "+
            "FROM book AS s LEFT JOIN borrow_book AS ps ON s.book_id = ps.book_id "+
            "GROUP BY s.name, s.number_id ORDER BY 3 desc; ")

    List<BookBorrow> bookBorrows();

    Book findByBookId(long theId);
}
